import type { ConsultType } from '../enums'
import type { ConsultIllness, PartialConsult } from './../types/consult'
import { defineStore } from 'pinia'
import { computed, ref } from 'vue'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    const consult = ref<PartialConsult>({})

    const isNotEmpty = computed(() => {
      return (
        consult.value.illnessDesc ||
        consult.value.illnessTime ||
        consult.value.consultFlag !== undefined
      )
    })

    const setType = (type: ConsultType) => {
      consult.value.type = type
    }

    const setIllnessType = (type: 0 | 1) => {
      consult.value.illnessType = type
    }

    const setDepId = (id: string) => {
      consult.value.depId = id
    }

    const setIllness = (data: ConsultIllness) => {
      consult.value.illnessDesc = data.illnessDesc
      consult.value.illnessTime = data.illnessTime
      consult.value.consultFlag = data.consultFlag
      consult.value.pictures = data.pictures
    }

    const setPatinetId = (id: string) => {
      consult.value.patientId = id
    }

    const clear = () => {
      consult.value = {}
    }

    return {
      consult,
      setType,
      setIllnessType,
      setDepId,
      setIllness,
      setPatinetId,
      clear,
      isNotEmpty
    }
  },
  { persist: true }
)
